package com.github.freewu.commons.utils;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.NotificationCompat;

/**
 * Created by free on 16-10-8.
 */

public class NotificationUtils {
    /**
     *
     * @param context Context
     * @param title 标题
     * @param message 内容
     * @param smallIco 小图标
     * @param largeIco 大图标
     */
    public static void showNotification(Context context, String title, String message, Intent contentIntent, int smallIco, Bitmap largeIco) {
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        int id = (int) (System.currentTimeMillis() / 1000);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

        PendingIntent pendingIntent = PendingIntent.getActivity(context,id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification notification=builder.setContentTitle(title)
                .setContentText(message)
                .setTicker(title)
                .setWhen(System.currentTimeMillis())
                .setPriority(Notification.PRIORITY_MAX)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setSmallIcon(smallIco)
                .setLargeIcon(largeIco)
                .setContentIntent(pendingIntent)
                .build();

        notification.flags=Notification.FLAG_AUTO_CANCEL;

        mNotificationManager.notify(id,notification);
    }
}
